﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FanaticInstaller.ViewModels;

namespace FanaticInstaller.Views
{
    /// <summary>
    /// InstallingView.xaml 的交互逻辑
    /// </summary>
    public partial class InstallingView : UserControl
    {
        private Task _loopSlideTask;
        public InstallingView()
        {
            InitializeComponent();
            _loopSlideTask = new Task(LoopSlideCallback);
            _loopSlideTask.Start();
        }

        private void LoopSlideCallback()
        {
            var slideImageIndex = 0;
            while (true)
            {
                Thread.Sleep(2000);
                var dataContext = MainViewModel.Instance;

                slideImageIndex = (slideImageIndex + 1) % dataContext.SlideImages.Count;
                var imageUri = dataContext.SlideImages[slideImageIndex];

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    PART_SlideImageContainer.PushFromLeft(imageUri);
                }));
            }

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PART_SlideImageContainer.PushFromLeft(new Uri(@"pack://application:,,,/FanaticInstaller;component/Resources/东方风神录.jpg"));
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            PART_SlideImageContainer.PushFromRight(new Uri(@"pack://application:,,,/FanaticInstaller;component/Resources/东方地灵殿.webp"));
        }
    }
}
